package test

import (
	"fmt"

	"nosqlx/consulx"

	"github.com/hashicorp/consul/api"
	"github.com/onsi/ginkgo/v2"
	"github.com/onsi/gomega"
)

var _ = ginkgo.Describe("client", ginkgo.Ordered, func() {
	ginkgo.Describe("client", func() {
		ginkgo.It("consul client", func() {
			client, err := consulx.ConsulClient()
			gomega.Expect(err).To(gomega.BeNil())
			gomega.Expect(client).NotTo(gomega.BeNil())

			nodes, _, err := client.Catalog().Nodes(&api.QueryOptions{})
			gomega.Expect(err).To(gomega.BeNil())

			for _, node := range nodes {
				fmt.Printf("check:%+v\n", node)
			}

			health := client.Health()
			node, _, err := health.Node(nodes[0].Node, &api.QueryOptions{})

			gomega.Expect(err).To(gomega.BeNil())
			for i, check := range node {
				fmt.Println("check", i, check.Node, check.Name)
			}

		})
	})
})
